using System;
using System.Collections.Generic;
using Nvigorate.Extensions;

namespace Nvigorate.Repository.Test
{
    public class NotificationBroker : INotificationBroker
    {
        private IList<NotificationScope> _activeScope = new List<NotificationScope>();
        
        public void RegisterScope(NotificationScope scope)
        {
            _activeScope.Add(scope);
        }

        public void DisposeScope(NotificationScope scope)
        {
            if (!_activeScope.Contains(scope))
                _activeScope.Remove(scope);
        }

        public void Dispatch(IDomainNotification notification)
        {
            _activeScope.ForEach(s => s.AddNotification(notification));
        }
    }
}